<template>

  <div class="layui-fulid" id="house-login">
    <div class="layui-form">
      <p>手机号登录  </p>

      <div class="layui-input-block login">
        <i class="layui-icon layui-icon-username"></i>
        <input type="text" required lay-verify="required" v-model="pojo.mobile" placeholder="请输入手机号码" class="layui-input">
      </div>

      <div class="layui-input-block login">
        <i class="layui-icon layui-icon-vercode"></i>
        <input type="text" required lay-verify="required" v-model="pojo.password"  placeholder="请输入密码" class="layui-input">
      </div>

      <div class="layui-input-block getCode">
        <input type="text" required lay-verify="required" placeholder="请输入验证码" class="layui-input">
        <button class="layui-btn">获取验证码</button>
      </div>
      <button class="layui-btn" @click="login" lay-submit lay-filter="user-login">登录</button>
    </div>
  </div>

</template>

<script>
  import userApi from '@/api/user'
  import { setUser } from '@/utils/auth'
  export default {
    data(){
      return {
        pojo: {
          "loginType":"PC",
          "deviceInfor":"LENOVO-PC"
        }
      }
    },
    methods: {
      login(){
        userApi.login( this.pojo ).then(res => {
          if(res.data.flag){
            this.$message({
              message: '登录成功',
              type: 'success'
            })
            //保存用户信息
            setUser(res.data.data.token, res.data.data.name, res.data.data.avatar)
            this.pojo={}
          }else{
            this.$message({
              message: res.data.msg,
              type: 'error'
            })
          }
        })
      }
    }
  }
</script>
